<?php
namespace Home\Controller;

use Think\Controller;

class IndexController extends Controller
{

//     public function index()
//     {
        
        
        
//         $Info = M('Info');
//         $where = "type='invitejob'";
//         $count = $Info->where($where)->count();
//         $pagecount = 1;
//         $page = new \Think\Page($count , $pagecount);
//         //$page->parameter = $row; //此处的row是数组，为了传递查询条件
//         $page->setConfig('header','共 %TOTAL_ROW% 条记录');
//         $page->setConfig('first','首页');
//         $page->setConfig('prev','上一页');
//         $page->setConfig('next','下一页');
//         $page->setConfig('last','尾页');
//         $page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
//         $show = $page->show();
//         $list = $Info->where($where)->order('id desc')->limit($page->firstRow.','.$page->listRows)->select();
//         $this->assign('list',$list);
//         $this->assign('page',$show);
//         $this->display('index');
      
//    }
    //导航分类显示信息
    public function index()
    {   
        
        
        
        $ad=getAd();
        //var_dump($ad);exit();
        if(count($ad)>0){
        $this->assign("ad",$ad);
        }else{
            $ad=array(array('title'=>'<a disabled="true">暂时还没有任何广告信息！！！</a>'));
            $this->assign("ad",$ad);
        }
        $Info = D('Info');
        $field=$Info->getInfoField();
        $type= $_GET['type'];
        //$kw=$_GET['kw'];
        $map['type']=array('eq',$type);
        $state['checkstate']=array('eq',1);
        //$map['_logic'] = 'and';
//         $map['_complex'] = $where;
       // $where['_complex'] = $map;
        
        //$where['title|content|linkman']  = array('like','%'."$kw".'%');
//         $where['content']  = array('like','%'."$kw".'%');
//         $where['linkman']  = array('like','%'."$kw".'%');
        //$where['_logic'] = 'or';
       // var_dump($type) ;EXIT;
        if(!S('count'.$type.$_GET['p'])){//判断count是否有缓存，用count+类型名+分页值作为缓存名
            if(isset($type)&& !S('count'.$type.$_GET['p'])){
                    
                    $count = $Info->where($map)->where($state)->count();
                    echo $count;
                    S('count'.$type.$_GET['p'],$count);
            }else  {
                $count = $Info->where($state)->count();
                echo $count.'all';
                S('count'.$type.$_GET['p'],$count);
            }
        }
        $count=S("count".$type.$_GET['p']);
       //ECHO $count;EXIT;
       $Page=getMyPage($count,4);//调用分页函数
        
         //var_dump(S('list'));exit();
         if(!S('list'.$type.$_GET['p'])){//判断list是否有缓存，用list+类型名+分页值作为缓存名
           //  echo '缓存一下先';
             if(isset($type)&& !S('list'.$type.$_GET['p'])){
                 echo '缓存'.$type.$_GET['p'];
                     $list  = $Info->field($field)->where($map)->where($state)->order('edate desc')->limit($Page->firstRow.','.$Page->listRows)->select();  
                     S('list'.$type.$_GET['p'],$list) ;        
             }else {
                 echo '缓存'.$type.$_GET['p'];
                 $list  = $Info->field($field)->where($state)->order('edate desc')->limit($Page->firstRow.','.$Page->listRows)->select();
                 S('list'.$type.$_GET['p'],$list);
             }
         
         }
         
         $show = $Page->show();//调用分页show方法
         $list = S('list'.$type.$_GET['p']);//取得缓存到的值赋给变量$list
         
        // $info=$info->query($sql);
       // $info->getCondition;
       // $condition=$info->condition;
        //print_r($condition);
        //print_r($info);
        
        //echo 'd';exit();
//         $info = $info->field($condition)
//             ->page($_GET['p'], 5)
//             ->select();
        $this->assign("list", $list);
        
        $this->assign("page", $show);
        //var_dump($list);exit();
        if (count($list)>0){
        $this->display("index");
        }else{
            $this->assign("msg","对不起没有查询到您要的信息!!!");
            $this->display("msg");
        }
    }
    
//     public function searchInfo()
//     {
//         //echo $_POST['kw'];exit;
//         $Info = D('Info');
//         $field=$Info->getInfoField();
//         $type= $_POST['type'];
//         var_dump($type);
//         $where='type="'.$type.'"';
//         $kw=$_POST['kw'];
        
//         //$map['content']  = array('like','%"'.$kw.'" %');
//         $map['type']=$type;
//         // var_dump($type) ;EXIT;
//         if(isset($type)){
//             $count      = $Info->where($where)->count();
//         }else {
//             $count      = $Info->count();
//         }
        
//         //ECHO $count;EXIT;
//         $Page=getMyPage($count,4);
//         $show       = $Page->show();
//         //var_dump($show);exit();
//        // if(isset($type)){
//            // echo "111";exit();
//             $list  = $Info->field($field)->where($where)->order('edate')->limit($Page->firstRow.','.$Page->listRows)->select();
//        // }else {
//            // echo "222";exit();
//        //     $list  = $Info->field($field)->order('edate')->limit($Page->firstRow.','.$Page->listRows)->select();
//        // }
//        // var_dump($list) ;var_dump($type) ;
//         // $info=$info->query($sql);
//         // $info->getCondition;
//         // $condition=$info->condition;
//         //print_r($condition);
//         //print_r($info);
    
//         //echo 'd';exit();
//         //         $info = $info->field($condition)
//         //             ->page($_GET['p'], 5)
//         //             ->select();
//         $this->assign("list", $list);
//         $this->assign("page", $show);
//         //var_dump($list);exit();
//         if (count($list)>0){
//             // echo "222";exit();
//             $this->display("index");
//         }else{
//             $this->assign("msg","对不起没有查询到您要的信息!!!");
//             $this->display("msg");
//         }
//     }
    
//     public function showAllUsers() {
//         $m = M('info');
//         $where = "id<100";
//         $count = $m->where($where)->count();
//         $p = getpage($count,1);
        
//         $list = $m->field(true)->where($where)->order('id')->limit($p->firstRow, $p->listRows)->select();
//         $this->assign('select', $list); // 赋值数据集
//         $this->assign('page', $p->show()); // 赋值分页输出
//         $this->display('index');
//     }
    //按关键词搜索
    public function searchKw()
    {   
//         $a="scs".$_GET['kw'];

//         var_dump(S($a));//exit();
//         if (S("scs".$_GET['kw'])===false){

//             S($a  ,  $_GET['kw'] );
//             //S("scs".$_GET['kw'],$_GET['kw']);
//             //$a=S("scs");
//         var_dump(S($a) );exit('hao');
        
//         }

//         exit('mb');
        
        $ad=getAd();
    if(count($ad)>0){
        $this->assign("ad",$ad);
        }else{
            $ad=array(array('title'=>'<a disabled="true">暂时还没有任何广告信息！！！</a>'));//没有广告就显示没有广告 且不能点击
            $this->assign("ad",$ad);
        }
    
        $Info = D('Info');
        $field=$Info->getInfoField();//获取列名
        $type= $_GET['type'];
        $kw=$_GET['kw'];
        $map['type']=array('eq',$type);
        //$map['_logic'] = 'and';
        //         $map['_complex'] = $where;
        // $where['_complex'] = $map;
    
        $where['title|content|linkman']  = array('like','%'."$kw".'%');
        //         $where['content']  = array('like','%'."$kw".'%');
        //         $where['linkman']  = array('like','%'."$kw".'%');
        //$where['_logic'] = 'or';
        // var_dump($type) ;EXIT;
        //var_dump(S("sCount"));
            if (!S("sCount".$type.$kw.$_GET['p'])){//判断查询的数量有没有缓存，没有的话执行下面语句
                $count = $Info->where($where)->where($map)->count();//满足查询条件的数据的个数
                //var_dump($count); //测试断点
                S("sCount".$type.$kw.$_GET['p'],$count);//把数量缓存
               // echo "sssssss";
            }
            $count=S("sCount".$type.$kw.$_GET['p']);
        //ECHO $count;EXIT;
        $Page=getMyPage($count,4);//调用分页类函数获得分页信息 数据个数和每页4条数据
        $show       = $Page->show();
        //var_dump($show);exit();
        if(!S("sList".$type.$kw.$_GET['p'])){ //判断查询的数据有没有缓存，没有的话执行下面语句
        $list  = $Info->field($field)->where($where)->where($map)->order('edate desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        //var_dump($list);//测试断点
        S("sList".$type.$kw.$_GET['p'],$list);//把查询到的数据缓存
        }
        $list = S("sList".$type.$kw.$_GET['p']);//把缓存里的值赋给list
        // $info=$info->query($sql);
        // $info->getCondition;
        // $condition=$info->condition;
        //print_r($condition);
        //print_r($info);
    
        //echo 'd';exit();
        //         $info = $info->field($condition)
        //             ->page($_GET['p'], 5)
        //             ->select();
        $this->assign("list", $list);
        
        $this->assign("page", $show);
        //var_dump($list);exit();
        if (count($list)>0){
            $this->display("index");
        }else{
            $this->assign("msg","对不起没有查询到您要的信息!!!");
            $this->display("msg");
        }
    }
}